package logics

import (
	"git.900sui.cn/kc/rpcPay/common/models"
	"git.900sui.cn/kc/rpcinterface/interface/order"
	"git.900sui.cn/kc/rpcinterface/interface/pay"
)

type InsureLogic struct {
}

//获取保险和续保的分账账号
func (i *InsureLogic) GetInsureAcct(args *pay.ArgsGetInsureAcct, reply *pay.ReplyGetInsureAcct) (ere error) {
	*reply = pay.ReplyGetInsureAcct{
		Insure: pay.InsureAcc{
			AcctName:   "",
			AcctNo:     "",
			MerchantId: "",
		},
		RenewInsure: pay.InsureAcc{
			AcctName:   "",
			AcctNo:     "",
			MerchantId: "",
		},
	}

	switch args.PayChannel {
	case order.PAY_CHANNEL_sand:
		mSand := new(models.InsureSandpayModel).Init()
		mRenewSand := new(models.RenewInsureSandpayModel).Init()

		info := mSand.GetByInsureId(args.InsureChannel)
		renewInfo := mRenewSand.GetByInsureId(args.InsureChannel)

		if len(info) > 0 {
			reply.Insure.AcctNo = info[mSand.Field.F_acct_no].(string)
			reply.Insure.AcctName = info[mSand.Field.F_acct_name].(string)
		}
		if len(renewInfo) > 0 {
			reply.RenewInsure.AcctName = renewInfo[mRenewSand.Field.F_acct_name].(string)
			reply.RenewInsure.AcctNo = renewInfo[mRenewSand.Field.F_acct_no].(string)
		}
	case order.PAY_CHANNEL_pingan:
		mPingan := new(models.InsurePinganModel).Init()
		mRenewPingan := new(models.RenewInsurePinganModel).Init()
		info := mPingan.GetByInsureid(args.InsureChannel)
		renewInfo := mRenewPingan.GetByInsureid(args.InsureChannel)

		if len(info) > 0 {
			reply.Insure.AcctNo = info[mPingan.Field.F_acct_no].(string)
			reply.Insure.AcctName = info[mPingan.Field.F_acct_name].(string)
			reply.Insure.MerchantId = info[mPingan.Field.F_merchant_id].(string)
		}
		if len(renewInfo) > 0 {
			reply.RenewInsure.AcctName = renewInfo[mRenewPingan.Field.F_acct_name].(string)
			reply.RenewInsure.AcctNo = renewInfo[mRenewPingan.Field.F_acct_no].(string)
			reply.RenewInsure.MerchantId = renewInfo[mRenewPingan.Field.F_merchant_id].(string)
		}
	}

	return
}
